package labox.innovation.gameserver.network.clientpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.gameserver.network.L2GameClient;
import labox.innovation.gameserver.network.serverpackets.L2GameServerPacket;
import labox.innovation.netcore.ReceivablePacket;

/**
 * Packets received by the game server from clients
 * 
 * @author KenM
 */
public abstract class L2GameClientPacket extends ReceivablePacket<L2GameClient> {

	private static final Logger _log = LoggerFactory.getLogger(L2GameClientPacket.class.getName());

	/*------------------------------登陆部分协议---------------------------------------*/
	public static final int PTL_TESTPOROCAL=0X1;
	
	/**
	 * -- 协议版本检查
	 */
	public static final int PTL_PROTOCOLVERSION = 0x10;

	/**
	 * -- 玩家登陆鉴权
	 */
	public static final int PTL_AUTHLOGIN = PTL_PROTOCOLVERSION + 0x01;

	/**
	 * -- 创建角色
	 */
	public static final int PTL_NEWCHARACTER = PTL_PROTOCOLVERSION + 0x02;

	/**
	 * -- 创建角色请求
	 */
	public static final int PTL_CHARACTERCREAT = PTL_PROTOCOLVERSION + 0x03;

	/**
	 * -- 进入世界请求
	 */
	public static final int PTL_ENTERWORLD = PTL_PROTOCOLVERSION + 0x04;

	/**
	 * 删除角色
	 */
	public static final int PTL_CHARACTERDELETE = PTL_PROTOCOLVERSION + 0x05;

	/**
	 * 回复角色
	 */
	public static final int PTL_CHARACTERRESTORE = PTL_PROTOCOLVERSION + 0x06;

	/**
	 * 登出游戏
	 */
	public static final int PTL_LOGOUT = PTL_PROTOCOLVERSION + 0x07;
	
	/**
	 * 回应心跳
	 */
	public static final int PTL_GAMEGUARDREPLY = PTL_PROTOCOLVERSION + 0x08;

	/*------------------------------场景部分协议---------------------------*/

	/**
	 * 请求注册快捷
	 */
	public static final int PTL_REQUESTSHORTCUTREG = 0x20;

	/**
	 * 请求删除快捷
	 */
	public static final int PTL_REQUESTSHORTCUTDEL = PTL_REQUESTSHORTCUTREG + 0x01;

	/**
	 * 请求角色的详细信息
	 */
	public static final int PTL_REQUESTUSERINFO = PTL_REQUESTSHORTCUTREG + 0x02;

	/**
	 * 请求启用/禁用自动升级功能
	 */
	public static final int PTL_REQUESTAUTOLEVELUP = PTL_REQUESTSHORTCUTREG + 0x03;

	/**
	 * 客户端请求升级
	 */
	public static final int PTL_REQUESTLEVELUP = PTL_REQUESTSHORTCUTREG + 0x04;

	/**
	 * 客户端请求加点
	 */
	public static final int PTL_REQUESTASSUGNPOINT = PTL_REQUESTSHORTCUTREG + 0x05;

	/**
	 * 查找当前场景的所有玩家、NPC
	 */
	public static final int PTL_REQUESTNEARBYPLAYER = PTL_REQUESTSHORTCUTREG + 0x06;

	/**
	 * 邀请加入队伍
	 */
	public static final int PTL_REQUESTJOINPARTY = PTL_REQUESTSHORTCUTREG + 0x07;

	/**
	 * 响应邀请加入队伍请求
	 */
	public static final int PTL_REQUESTANSWERJOINPARTY = PTL_REQUESTSHORTCUTREG + 0x08;

	/**
	 * 申请离开队伍
	 */
	public static final int PTL_REQUESTOUTPARTYMEMBER = PTL_REQUESTSHORTCUTREG + 0x09;

	/**
	 * 申请解散队伍
	 */
	public static final int PTL_REQUESTDISBANDPARTY = PTL_REQUESTSHORTCUTREG + 0x0a;

	/**
	 * 查看队伍列表信息
	 */
	public static final int PTL_REQUESTPARTYINFO = PTL_REQUESTSHORTCUTREG + 0x0b;

	/**
	 * 设置队伍信息
	 */
	public static final int PTL_SETPARTYINFO = PTL_REQUESTSHORTCUTREG + 0x0c;

	/**
	 * 更改队伍分配方式
	 */
	public static final int PTL_REQUESTCHANGEPARTYMODE = PTL_REQUESTSHORTCUTREG + 0x0d;

	/**
	 * 客户端 获得技能树
	 */
	public static final int PTL_REQUESTPCSKILLLIST = PTL_REQUESTSHORTCUTREG + 0x0e;

	/**
	 * 客户端学习技能
	 */
	public static final int PTL_REQUESTAQUIRESKILL = PTL_REQUESTSHORTCUTREG + 0x0f;

	/**
	 * 客户端请求快捷方式列表
	 */
	public static final int PTL_REQUESTSHORTCUTLIST = PTL_REQUESTSHORTCUTREG + 0x10;

	/**
	 * 客户端请求 技能描述
	 */
	public static final int PTL_REQUESTSKILLINFO = PTL_REQUESTSHORTCUTREG + 0x12;

	/**
	 * 客户端请求任务列表
	 */
	public static final int PTL_REQUESTQUESTLIST = PTL_REQUESTSHORTCUTREG + 0x13;

	/**
	 * 客户端请求任务查看
	 */
	public static final int PTL_REQUESTQUESTSELECT = PTL_REQUESTSHORTCUTREG + 0x14;

	/**
	 * 客户端请求放弃任务
	 */
	public static final int PTL_REQUESTQUESTABORT = PTL_REQUESTSHORTCUTREG + 0x15;

	/**
	 * 客户端请求排行榜榜单信息
	 */
	public static final int PTL_RANK_LIST = PTL_REQUESTSHORTCUTREG + 0x16;

	/**
	 * 客户端请求排行榜信息
	 */
	public static final int PTL_RANK = PTL_REQUESTSHORTCUTREG + 0x17;

	/**
	 * NPC交易客户端请求买/卖物品
	 */
	public static final int PTL_REQUESTMERCHANT = PTL_REQUESTSHORTCUTREG + 0x18;
	
	/**
	 * 客户端请求世界地图
	 */
	public static final int PTL_REQUESTWORLDMAP = PTL_REQUESTSHORTCUTREG + 0x19;
	
	/**
	 * 客户端请求雷达开启/关闭
	 */
	public static final int PTL_RADARINFO = PTL_REQUESTSHORTCUTREG + 0x1A;
	/*------------------------------战斗交互部分协议---------------------------*/

	/**
	 * 攻击请求
	 */
	public static final int PTL_ATTACKREQUEST = 0x50;

	/**
	 * 请求攻击取消
	 */
	public static final int PTL_ATTACKCANCLE = PTL_ATTACKREQUEST + 1;

	/**
	 * 请求交互
	 */
	public static final int PTL_ACTION = PTL_ATTACKREQUEST + 2;

	/**
	 * 请求重生
	 */
	public static final int PTL_REQUESTRESTARTPOINT = PTL_ATTACKREQUEST + 3;

	/**
	 * 同步坐标
	 */
	public static final int PTL_LOCATION = PTL_ATTACKREQUEST + 4;

	/**
	 * 请求服务
	 */
	public static final int PTL_REQUESTBYPASSTOSERVER = PTL_ATTACKREQUEST + 5;

	public static final int PTL_REQUESTMAGICSKILLUSE = PTL_ATTACKREQUEST + 6;

	/**
	 * 请求角色效果状态
	 */
	public static final int PTL_REQUESTEFFECTBUFF = PTL_ATTACKREQUEST + 0x07;

	/**
	 * 客户端请求结束某个效果状态
	 */
	public static final int PTL_REQUESTSTOPEFFECT = PTL_ATTACKREQUEST + 0x08;

	/**
	 * 客户端请求更改PK模式
	 */
	public static final int PTL_REQUESTCAHNGEPKMODEL = PTL_ATTACKREQUEST + 0x09;

	/**
	 * 客户端请求自动战斗配置信息
	 */
	public static final int PTL_GETAUTOATTACKINFO = PTL_ATTACKREQUEST + 0x0a;

	/**
	 * 客户端提交自动战斗配置信息
	 */
	public static final int PTL_AUTOATTACKSET = PTL_ATTACKREQUEST + 0x0b;

	/**
	 * 客户端请求自动战斗状态 0 关闭 1开启
	 */
	public static final int PTL_AUTOATTACKSTATE = PTL_ATTACKREQUEST + 0x0c;

	/*------------------------------道具部分协议---------------------------*/

	/**
	 * 请求背包
	 */
	public static final int PTL_REQUESTITEMLIST = 0x70;

	/**
	 * 请求物品信息
	 */
	public static final int PTL_REQUESTEXRQITEMLINK = PTL_REQUESTITEMLIST + 1;

	/**
	 * 请求使用物品
	 */
	public static final int PTL_USEITEM = PTL_REQUESTITEMLIST + 2;

	/**
	 * 请求交易
	 */
	public static final int PTL_TRADEREQUEST = PTL_REQUESTITEMLIST + 3;

	/**
	 * 回应交易请求
	 */
	public static final int PTL_ANSWERTRADEREQUEST = PTL_REQUESTITEMLIST + 4;

	/**
	 * 客户端请求物品改变
	 */
	public static final int PTL_CHANGETRADEITEM = PTL_REQUESTITEMLIST + 5;

	/**
	 * 客户端请求锁定
	 */
	public static final int PTL_TRADELOCK = PTL_REQUESTITEMLIST + 6;

	/**
	 * 客户端请求交易
	 */
	public static final int PTL_TRADEDONE = PTL_REQUESTITEMLIST + 7;

	/**
	 * 客户端卸载装备
	 */
	public static final int PTL_REQUESTUNEQUIPITEM = PTL_REQUESTITEMLIST + 8;

	/**
	 * 客户端 丢弃物品
	 */
	public static final int PTL_REQUESTDROPITEM = PTL_REQUESTITEMLIST + 9;

	/**
	 * 客户端请求物品移动
	 */
	public static final int PTL_WAREHOUSE_INVENTORY_MOVE = PTL_REQUESTITEMLIST + 10;

	/**
	 * 客户端请求鉴定 或 铭刻装备
	 */
	public static final int PTL_REQUESTIDENTIFYITEM = PTL_REQUESTITEMLIST + 0x0b;

	/**
	 * 客户端请求追星
	 */
	public static final int PTL_REQUESTSTARITEM = PTL_REQUESTITEMLIST + 0x0c;

	/**
	 * 客户端请求合成物品
	 */
	public static final int PTL_REQUESTCOMPOSITEITEM = PTL_REQUESTITEMLIST + 0x0d;

	/**
	 * 客户端请求锻造物品
	 */
	public static final int PTL_REQUESTFORGEITEM = PTL_REQUESTITEMLIST + 0x0e;

	/**
	 * 客户端锻造物品操作
	 */
	public static final int PTL_REQUESTFORGEITEMCHANGE = PTL_REQUESTITEMLIST + 0x0f;

	/**
	 * 客户端请求商城列表协议
	 */
	public static final int PTL_SHOP_LIST = PTL_REQUESTITEMLIST + 0x10;

	/**
	 * 客户端请求商城协议
	 */
	public static final int PTL_SHOP = PTL_REQUESTITEMLIST + 0x11;

	/*-----------------------------好友系统部分协议---------------------------------*/
	/**
	 * 请求好友列表
	 */
	public static final int PTL_REQUESTFRIENDLIST = 0xA0;

	/**
	 * 请求添加好友
	 */
	public static final int PTL_REQUESTADDFRIEND = PTL_REQUESTFRIENDLIST + 1;

	/**
	 * 删除好友
	 */
	public static final int PTL_REQUESTDELFRIEND = PTL_REQUESTFRIENDLIST + 2;

	/**
	 * 征友
	 */
	public static final int PTL_REQUESTSEARCHFRIEND = PTL_REQUESTFRIENDLIST + 3;

	/**
	 * 好友动态
	 */
	public static final int PTL_REQUESTFRIENDNEWS = PTL_REQUESTFRIENDLIST + 4;

	/**
	 * 设置基本信息
	 */
	public static final int PTL_REQUESTSETINFO = PTL_REQUESTFRIENDLIST + 6;

	/*-------------------------------寄售系统-------------------------------------*/

	/**
	 * 请求寄售UI
	 */
	public static final int PTL_REQUESTCONSIGNMENTUI = 0xB0;

	/**
	 * 请求可上架物品
	 */
	public static final int PTL_REQUESTCANSHELVEITEMS = PTL_REQUESTCONSIGNMENTUI + 1;

	/**
	 * 请求背包物品上架
	 */
	public static final int PTL_REQUESTSHELVEITEMS = PTL_REQUESTCONSIGNMENTUI + 2;

	/**
	 * 请求物品下架
	 */
	public static final int PTL_REQUESTSHELFITEMS = PTL_REQUESTCONSIGNMENTUI + 3;

	/**
	 * 请求取回下架物品
	 */
	public static final int PTL_FETCHITEMOCNSIGNMENT = PTL_REQUESTCONSIGNMENTUI + 4;

	/**
	 * 购买寄售物品
	 */
	public static final int PTL_BUYITEMCONSIGNMENT = PTL_REQUESTCONSIGNMENTUI + 5;

	/**
	 * 请求下架物品上架
	 */
	public static final int PTL_REQUESTSHELVEOFSHELFITEM = PTL_REQUESTCONSIGNMENTUI + 6;

	/**
	 * 根据类别查找寄售物品
	 */
	public static final int PTL_REQUESCONITEMBYCATEGORY = PTL_REQUESTCONSIGNMENTUI + 7;

	/**
	 * 高级查找寄售物品
	 */
	public static final int PTL_REQUESCONITEMHIGH = PTL_REQUESTCONSIGNMENTUI + 8;

	/**
	 * 请求结果翻页
	 */
	public static final int PTL_REQUESTPAGETURING = PTL_REQUESTCONSIGNMENTUI + 9;

	/*---------------------------------聊天系统-----------------------------------*/

	public static final int PTL_CHAT = 0x90;
	
	public static final int PTL_CHAT_SWITCH = PTL_CHAT + 1;  //-- 聊天开关设置协议，临时测试用
	
	/*---------------------------------充值系统-----------------------------------*/
	
	/***
	 * 请求充值列表
	 */
	public static final int PTl_RECHARGE_List = 0x95;
	/***
	 * 用户请求充值
	 */
	public static final int PTL_RECHARGE = PTl_RECHARGE_List + +0x01;

	@Override
	protected boolean read() {
		//_log.info(this.getType());
		try {
			readImpl();
			return true;
		} catch (Exception e) {
			_log.error("Client: " + getClient().toString() + " - Failed reading: " + getType() + " - Innovation Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION, Config.SERVER_ID, e);
		}
		return false;
	}

	protected abstract void readImpl();

	public void run() {
		try {
			runImpl();
		} catch (Throwable t) {
			_log.error("Client: " + getClient().toString() + " - Failed running: " + getType() + " - Innovation Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION, Config.SERVER_ID, t);
		}
	}

	protected abstract void runImpl();

	protected final void sendPacket(L2GameServerPacket gsp) {
		getClient().sendPacket(gsp);
	}

	/**
	 * @return A String with this packet name for debuging purposes
	 */
	public abstract String getType();
}
